<?php
namespace LowCode;

use LowCode\Assets\AssetBuilder;

class Asset
{
    private static Asset $instance;

    private AssetBuilder $assets;

    /**
     *
     */
    public function __construct()
    {
        $this->assets = new AssetBuilder;
    }

    /**
     * @return Asset
     */
    public static function make(): Asset
    {
        if (!isset(self::$instance) || !(self::$instance instanceof self)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * @param string|array $css
     * @param string|null $namespace
     * @return AssetBuilder
     */
    public static function css(string|array $css, string $namespace = null): AssetBuilder
    {
        $asset = self::make();
        return $asset->assets->add($css, $namespace);
    }

    /**
     * @param string|array $js
     * @param string|null $namespace
     * @return AssetBuilder
     */
    public static function js(string|array $js, string $namespace = null): AssetBuilder
    {
        $asset = self::make();
        return $asset->assets->add($js, $namespace);
    }

    public function getAssets(): AssetBuilder
    {
        return $this->assets;
    }

    public function getCss(): string
    {
        return $this->assets->css();
    }

    public function getJs(): string
    {
        return $this->assets->js();
    }

    /**
     * @return string
     */
    public static function loadCss(): string
    {
        return self::make()->getCss();
    }

    /**
     * @return string
     */
    public static function loadJs(): string
    {
        return self::make()->getJs();
    }
}
